package com.wry.wry_test.algorithm;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: wangrongyi
 * @Date: 2024/11/18 9:55
 * @Description:
 */
public class Day09 {

    public static int solution(int[] array) {
        // Edit your code here
        Map<Integer, Integer> countMap = new HashMap<>();
        for (int i : array) {
            countMap.put(i, countMap.getOrDefault(i, 0) + 1);
        }
        int size = array.length;
        return countMap.entrySet().stream()
                .filter(entry -> entry.getValue() > size / 2)
                .findFirst()
                .map(Map.Entry::getKey)
                .orElse(0);
    }

    public static void main(String[] args) {
        // Add your test cases here

        System.out.println(solution(new int[]{1, 3, 8, 2, 3, 1, 3, 3, 3}) == 3);
    }


}
